package com.yotta.operationdatascreencode.common.core;

import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.v3.oas.annotations.media.Schema;
import java.util.List;
import javax.validation.constraints.NotEmpty;

/**
 * 分页返回参数工具类
 * @param <T> 泛型
 */
@Schema(description = "分页响应参数")
public class BasePageResult<T> {
    @NotEmpty
    @Schema(description = "结果集")
    private List<T> data;

    @NotEmpty
    @Schema(description = "总记录数", required = true)
    private Long totalNum;

    @NotEmpty
    @Schema(description = "当前第几页", required  = true)
    private Long pageNum;

    @NotEmpty
    @Schema(description = "总页数", required = true)
    private Long pageSize;

    /**
     * 构造方法
     * @param data 数据
     * @param totalNum 总页数
     * @param pageNum 当前页
     * @param pageSize 每页条数
     */
    public BasePageResult(List<T> data, Long totalNum, Long pageNum, Long pageSize) {
        this.data = data;
        this.totalNum = totalNum;
        this.pageNum = pageNum;
        this.pageSize = pageSize;
    }

    /**
     * 实例化
     * @param page 分页
     * @param <E> 类型
     * @return 返回值
     */
    public static <E> BasePageResult<E> newInstance(IPage<E> page) {
        return new BasePageResult<E>(page.getRecords(), page.getTotal(),
                page.getCurrent(), page.getSize());
    }

    public List<T> getData() {
        return data;
    }

    public Long getTotalNum() {
        return totalNum;
    }

    public Long getPageNum() {
        return pageNum;
    }

    public Long getPageSize() {
        return pageSize;
    }

    public void setData(List<T> data) {
        this.data = data;
    }

    public void setTotalNum(Long totalNum) {
        this.totalNum = totalNum;
    }

    public void setPageNum(Long pageNum) {
        this.pageNum = pageNum;
    }

    public void setPageSize(Long pageSize) {
        this.pageSize = pageSize;
    }
}
